package badugaclient;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class GuiCards extends JPanel 
{
	
	private JLabel card1;
	private JLabel card2;
	private JLabel card3;
	private JLabel card4;
	private JButton b1 = new JButton("Exchange");
	private JCheckBox[] checkBox = new JCheckBox[4];
	private PlayerInfo pInfo;
	private Gui gui;
	private JLabel winner = new JLabel("Winner is:");
	
	private String[] hand = new String[4];
	
	public GuiCards(Gui gui, PlayerInfo pInfo)
	{
		super();
		this.gui = gui;
		this.pInfo = pInfo;
		
		//setSize(300,150);
		setLayout(null);
		

	
		card1 = new JLabel(hand[0]);
		add(card1);
		card1.setBounds(0, 20, 150, 20);
		
		card2 = new JLabel(hand[1]);
		add(card2);
		card2.setBounds(95, 35, 150, 20);
	
		card3 = new JLabel(hand[2]);
		add(card3);
		card3.setBounds(190, 20, 150, 20);
	
		card4 = new JLabel(hand[3]);
		add(card4);
		card4.setBounds(275, 35, 150, 20);
		
		for(int i = 0; i < 4; i++)
		{
			checkBox[i] = new JCheckBox();
		}
		
		add(checkBox[0]);
		checkBox[0].setBounds(20, 70, 50, 20);
		
		add(checkBox[1]);
		checkBox[1].setBounds(110, 70, 50, 20);
		
		add(checkBox[2]);
		checkBox[2].setBounds(200, 70, 50, 20);
		
		add(checkBox[3]);
		checkBox[3].setBounds(280, 70, 50, 20);
		
		add(b1);
		b1.setBounds(230, 120, 100, 100);
		b1.setEnabled(false);
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0)
			{
				setCheckBoxSelected();
				pInfo.setContent("Exchange");
				gui.setChanged();
				gui.notifyObservers();
			}
		});
		
		add(winner);
		winner.setBounds(0, 120, 250, 100);
		
	}
	
	public void setHand0(String card)
	{
		this.card1.setText(card);
	}
	public void setHand1(String card)
	{
		this.card2.setText(card);
	}
	public void setHand2(String card)
	{
		this.card3.setText(card);
	}
	public void setHand3(String card)
	{
		this.card4.setText(card);
	}
	
	public void setCheckBoxSelected()
	{
		for(int i = 0; i < 4; i++)
		{
			if(checkBox[i].isSelected() == true)
			{
				pInfo.setCardsToChange("T", i);
			}
			else
			{
				pInfo.setCardsToChange("F", i);
			}
			checkBox[i].setSelected(false);
		}
	}
	
	public void setExchangeEnabled()
	{
		b1.setEnabled(true);
	}
	
	public void setExchangeDisable()
	{
		b1.setEnabled(false);
	}
	
	public void setWinner(String Text)
	{
		winner.setText(Text);
	}
}
